var API_URL = 'https://cloud.rulaiyun.net/admin/public/index.php/'
// var util = require('./util.js');

// SESSIONID = 11
var requestHandler = {
  url: '',
  data: {},
  success: function (res) {
    // success  
  },
  fail: function () {
    // fail  
  },
}

//GET请求  
function GET(requestHandler) {
  request('GET', requestHandler)
}
//POST请求  
function POST(requestHandler) {
  request('POST', requestHandler)
}

function request(method, requestHandler) {
  //注意：可以对params加密等处理  
  let data = requestHandler.data;
  let url = requestHandler.url;
  // let Cookie = wx.getStorageSync('sessionId') ? "SESSIONID=" + wx.getStorageSync('sessionId'): "";
  wx.request({
    url: API_URL + url,
    data: data,
    method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT  
    header: {
      'content-type': 'application/json', // 默认值
      'Cookie': "SESSIONID=" + wx.getStorageSync('sessionId')
    }, // 设置请求的 header  
    success: function (res) {
      //注意：可以对参数解密等处理  
      requestHandler.success(res)
    },
    fail: function () {
      requestHandler.fail()
    },
    complete: function () {
      // complete  
    }
  })
}

module.exports = {
  GET: GET,
  POST: POST
}  